package com.huangliusong.countdown;

import java.util.concurrent.CountDownLatch;

/**
 * 抽象类 用于演示 危险化工品工车监控中心 统一检查
 * @author huangliusong
 * @since 2019/1/26
 * {@link Runnable}
 */
public abstract class DangerCenter implements Runnable {

    //计数器
    private CountDownLatch countDownLatch;
    //调度站
    private String station;
    //调度站针对当前自己的站点进行检查 是否检查ok的标志
    private boolean ok;


    public DangerCenter(CountDownLatch countDownLatch,String station){
        this.countDownLatch=countDownLatch;
        this.station=station;
        this.ok=false;
    }
    public void run() {
        try {
            check();
            ok=true;
        }catch (Exception e){
            e.printStackTrace();
            ok=false;
        }finally {
            if (countDownLatch!=null){
                countDownLatch.countDown();
            }
        }
    }

    public abstract void check();

    public CountDownLatch getCountDownLatch() {
        return countDownLatch;
    }

    public void setCountDownLatch(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }

    public String getStation() {
        return station;
    }

    public void setStation(String station) {
        this.station = station;
    }

    public boolean isOk() {
        return ok;
    }

    public void setOk(boolean ok) {
        this.ok = ok;
    }
}
